package com.box.ai.service.impl;

import com.box.ai.pojo.enums.ChatTypeEnum;
import com.box.ai.service.handler.ChatTypeHandler;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Component
public class FunctionTypeFactory implements InitializingBean {

    @Resource
    private List<ChatTypeHandler> chatTypeHandlers;

    private final HashMap<ChatTypeEnum, ChatTypeHandler> chatMap = new HashMap<>();

    public ChatTypeHandler getBean(String type){
        ChatTypeEnum chat = ChatTypeEnum.getByChat(type);
        return chatMap.get(chat);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        for (ChatTypeHandler chatTypeHandler : chatTypeHandlers) {
            chatMap.put(chatTypeHandler.geByType(),chatTypeHandler);
        }
    }
}
